package com.young.manager.controller;

import com.young.common.interf.IBaseController;
import com.young.common.model.ResultData;
import com.young.manager.model.CompanyDataBase;
import com.young.manager.service.CompanyDataBaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RequestMapping("companyDB")
@RestController
@Slf4j
@RequiredArgsConstructor
public class CompanyDatabaseController implements IBaseController {

    private final CompanyDataBaseService companyDataBaseService;

    @GetMapping
    ResultData<?> queryList(
            @RequestParam(required = false) Long companyId,
            @RequestParam(required = false) String name,
            @RequestParam(required = false) Integer pageNum,
            @RequestParam(required = false) Integer pageSize
    ) {
        pageNum = null == pageNum ? DEFAULT_PAG_ENUM : pageNum;
        pageSize = null == pageSize ? DEFAULT_PAGE_SIZE : pageSize;
        return success(companyDataBaseService.queryPage(companyId, name, pageNum, pageSize));
    }

    @PostMapping("insert")
    ResultData<?> insertCompanyDataBase(@RequestBody CompanyDataBase companyDataBase) {
        companyDataBaseService.insertCompanyDataBase(companyDataBase);
        return success();
    }

    @PostMapping("update")
    ResultData<?> updateCompanyDataBase(@RequestBody CompanyDataBase companyDataBase) {
        companyDataBaseService.updateCompanyDataBase(companyDataBase);
        return success();
    }

    @PostMapping("delete")
    ResultData<?> deleteCompanyDataBase(@RequestParam Long id) {
        companyDataBaseService.deleteCompanyDataBase(id);
        return success();
    }
}
